//
//  LGMineStatisticView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/22.
//  我的--服务统计

#import "LGMineStatisticView.h"

#define  item_W  (Screen_W-viewPix(32))/4.0
#define  item_H  viewPix(60)

@interface LGMineStatisticView()

/**   */
@property (nonatomic , strong)UILabel *mouthLabel;
/**   */
@property (nonatomic , strong)LGStatisticItemView *itemView1;
/**   */
@property (nonatomic , strong)LGStatisticItemView *itemView2;
/**   */
@property (nonatomic , strong)LGStatisticItemView *itemView3;
/**   */
@property (nonatomic , strong)LGStatisticItemView *itemView4;
/**   */
@property (nonatomic , strong)NSDateFormatter *formatter;

@end

@implementation LGMineStatisticView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.mouthLabel];
        [self addSubview:self.historyBtn];
        [self addSubview:self.itemView1];
        [self addSubview:self.itemView2];
        [self addSubview:self.itemView3];
        [self addSubview:self.itemView4];
    }
    return self;
}

-(void)setRoleType:(NSString *)roleType{
    _roleType = roleType;
    if([roleType isEqualToString:@"10"]){
        //医生
        self.historyBtn.hidden = NO;
        self.itemView1.title = @"签约患者";
        self.itemView2.title = @"线下复查";
        self.itemView3.title = @"视频咨询";
        self.itemView4.title = @"专家咨询";
    }else{
        //护士
        self.historyBtn.hidden = YES;
        self.itemView1.title = @"签约审核";
        self.itemView2.title = @"方案审核";
        self.itemView3.title = @"风险干预";
        self.itemView4.title = @"入院安排";
    }
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    if([self.roleType isEqualToString:@"10"]){
        //医生
        self.itemView1.count = LGNSString(dataDic[@"vip_count"]);
        self.itemView2.count = LGNSString(dataDic[@"clinic_count"]);
        self.itemView3.count = LGNSString(dataDic[@"video_count"]);
        self.itemView4.count = LGNSString(dataDic[@"expert_count"]);
        
        self.itemView1.status = LGNSString(dataDic[@"vip_count_up"]);
        self.itemView2.status = LGNSString(dataDic[@"clinic_count_up"]);
        self.itemView3.status = LGNSString(dataDic[@"video_count_up"]);
        self.itemView4.status = LGNSString(dataDic[@"expert_count_up"]);
    }else{
        self.itemView1.count = LGNSString(dataDic[@"vip_count"]);;
        self.itemView2.count = LGNSString(dataDic[@"case_count"]);
        self.itemView3.count = LGNSString(dataDic[@"risk_count"]);
        self.itemView4.count = LGNSString(dataDic[@"plan_count"]);
        
        self.itemView1.status = LGNSString(dataDic[@"vip_count_up"]);
        self.itemView2.status = LGNSString(dataDic[@"case_count_up"]);;
        self.itemView3.status = LGNSString(dataDic[@"risk_count_up"]);;
        self.itemView4.status = LGNSString(dataDic[@"plan_count_up"]);;
    }
}


-(NSDateFormatter *)formatter{
    if(!_formatter){
        _formatter = [[NSDateFormatter alloc] init];
        _formatter.dateFormat = @"yyyy-MM-dd";
    }
    return _formatter;
}

-(UILabel *)mouthLabel{
    if(!_mouthLabel){
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        NSDateComponents *component = [calendar components:NSCalendarUnitMonth fromDate:[NSDate date]];
        NSString *content = [NSString stringWithFormat:@"%ld月服务统计",component.month];
        _mouthLabel = [UILabel lableWithText:content colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _mouthLabel.frame = CGRectMake(viewPix(16), viewPix(16), viewPix(150), viewPix(25));
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:content];
        [attrStr addAttributes:@{NSFontAttributeName:LGFont(24)} range:NSMakeRange(0, content.length-5)];
        _mouthLabel.attributedText = attrStr;
    }
    return _mouthLabel;
}

-(UIButton *)historyBtn{
    if(!_historyBtn){
        _historyBtn = [UIButton buttonWithTitle:@"历史统计" titleFont:LGFontWeight(12, UIFontWeightMedium) textColor:@"#999999" imageName:@"grayTip12"];
        _historyBtn.frame = CGRectMake(Screen_W-viewPix(32)-viewPix(165), viewPix(14), viewPix(150), viewPix(30));
        _historyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_historyBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
    }
    return _historyBtn;
}


-(LGStatisticItemView *)itemView1{
    if(!_itemView1){
        _itemView1 = [[LGStatisticItemView alloc] initWithFrame:CGRectMake(0, viewPix(54), item_W, item_H)];
    }
    return _itemView1;
}

-(LGStatisticItemView *)itemView2{
    if(!_itemView2){
        _itemView2 = [[LGStatisticItemView alloc] initWithFrame:CGRectMake(item_W, kMinY(self.itemView1.frame), item_W, item_H)];
    }
    return _itemView2;
}

-(LGStatisticItemView *)itemView3{
    if(!_itemView3){
        _itemView3 = [[LGStatisticItemView alloc] initWithFrame:CGRectMake(item_W*2, kMinY(self.itemView1.frame), item_W, item_H)];
    }
    return _itemView3;
}

-(LGStatisticItemView *)itemView4{
    if(!_itemView4){
        _itemView4 = [[LGStatisticItemView alloc] initWithFrame:CGRectMake(item_W*3, kMinY(self.itemView1.frame), item_W, item_H)];
    }
    return _itemView4;
}

@end


#pragma mark
#pragma mark ====> LGStatisticItemView

@interface LGStatisticItemView()

/**   */
@property (nonatomic , strong)UILabel *countLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;

@end

@implementation LGStatisticItemView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
}

-(void)setCount:(NSString *)count{
    _count = count;
    self.countLabel.text = count;
}

-(void)setStatus:(NSString *)status{
    _status = status;
    [self.countLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self).offset(-viewPix(8));
    }];
    if([status isEqualToString:@"1"]){
        self.tipView.image = [UIImage imageNamed:@"我的-上升"];
        
    }else if ([status isEqualToString:@"-1"]){
        self.tipView.image = [UIImage imageNamed:@"我的-下降"];
        
    }else{
        self.tipView.image = [UIImage imageNamed:@""];
        [self.countLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
        }];
    }
}


-(void)createSubView{
    [self addSubview:self.countLabel];
    [self addSubview:self.tipView];
    [self addSubview:self.titleLabel];
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.titleLabel.mas_top).offset(-viewPix(5));
        make.centerX.equalTo(self).offset(-viewPix(8));
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.countLabel.mas_right);
        make.centerY.equalTo(self.countLabel);
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.centerX.equalTo(self);
        make.height.equalTo(@(viewPix(18)));
    }];
}

-(UILabel *)countLabel{
    if(!_countLabel){
        _countLabel = [UILabel lableWithText:@"0" colorString:@"#2E9AFC" textFont:LGFontWeight(18, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _countLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"我的-上升"]];
    }
    return _tipView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(13) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _titleLabel;
}


@end
